home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / Sentinel / Source / InfoMgr.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.7 KB  |  133 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <libc.h>
  5. #import <sys/time.h>
  6.  
  7. #import <appkit/Application.h>
  8. #import <appkit/View.h>
  9. #import <appkit/NXImage.h>
  10. #import <appkit/Panel.h>
  11. #import <soundkit/Sound.h>
  12.  
  13. #import "InfoMgr.h"
  14.  
  15.  
  16. void blinkTimerProc ( DPSTimedEntry teNumber, double now, char *userData )
  17. {
  18.     [ (id) userData blink ] ;
  19.     return ;
  20. }
  21.  
  22.  
  23. @implementation InfoMgr
  24.  
  25. - init
  26. {
  27.     standardIcon = [ NXImage findImageNamed: "Sentinel" ] ;
  28.     fuzzIcons [ 0 ] = [ NXImage findImageNamed: "Fuzz1" ] ;
  29.     fuzzIcons [ 1 ] = [ NXImage findImageNamed: "Fuzz2" ] ;
  30.     fuzzIcons [ 2 ] = [ NXImage findImageNamed: "Fuzz3" ] ;
  31.     blinkIcons [ 0 ] = [ NXImage findImageNamed: "Blink1" ] ;
  32.     blinkIcons [ 1 ] = [ NXImage findImageNamed: "Blink2" ] ;
  33.  
  34.     staticSound = [ Sound findSoundFor: "Static.snd" ] ;
  35.  
  36.     return [ super init ] ;
  37. }
  38.  
  39.  
  40. - openInfo: sender
  41. {
  42.     int                animationCounter ;
  43.     long                milTimer ;
  44.     struct timeval        tp ;
  45.     struct timezone    tzp ;
  46.  
  47.     if ( isInfoOpen )
  48.     {
  49.         return self ;
  50.     }
  51.  
  52.     [ infoIcon setFlipped: NO ] ;
  53.     [ infoPanel makeKeyAndOrderFront: self ] ;
  54.  
  55.     [ staticSound play ] ;
  56.     gettimeofday ( &tp,& tzp ) ;
  57.     milTimer = tp.tv_usec ;
  58.     for ( animationCounter = 0 ; animationCounter < 100 ; animationCounter++ )
  59.     {
  60.         while ( ( tp.tv_usec >= milTimer ) && ( tp.tv_usec < milTimer + 5000 ) )
  61.         {
  62.             gettimeofday ( &tp, &tzp ) ;
  63.         }
  64.         milTimer = tp.tv_usec ;
  65.         
  66.         [ self drawIcon: fuzzIcons [ animationCounter % 3 ] ] ;
  67.     }
  68.     [ self drawIcon: blinkIcons [ 0 ] ] ;
  69.  
  70.     blinkEntry = DPSAddTimedEntry ( 0.5, (DPSTimedEntryProc) blinkTimerProc, (void *) self,
  71.             NX_MODALRESPTHRESHOLD ) ;
  72.     isInfoOpen = YES ;    
  73.     return self ;
  74. }
  75.  
  76.  
  77. - windowWillClose: sender
  78. {
  79.     int                animationCounter ;
  80.     long                milTimer ;
  81.     struct timeval        tp ;
  82.     struct timezone    tzp ;
  83.     
  84.     isInfoOpen = NO ;
  85.     DPSRemoveTimedEntry ( blinkEntry ) ;
  86.  
  87.     [ staticSound play ] ;
  88.     gettimeofday ( &tp, &tzp ) ;
  89.     milTimer = tp.tv_usec ;
  90.     for ( animationCounter = 0 ; animationCounter < 100 ; animationCounter++ )
  91.     {
  92.         while ( ( tp.tv_usec >= milTimer ) && ( tp.tv_usec < milTimer + 5000 ) )
  93.         {
  94.             gettimeofday ( &tp, &tzp ) ;
  95.         }
  96.         milTimer = tp.tv_usec ;
  97.  
  98.         [ self drawIcon: fuzzIcons [ animationCounter % 3 ] ] ;
  99.     }
  100.     [ self drawIcon: standardIcon ] ;
  101.  
  102.     [ infoPanel orderOut: self ] ;
  103.  
  104.     return self ;
  105. }
  106.  
  107.  
  108. - blink
  109. {
  110.     [ self drawIcon: blinkIcons [ random ( ) % 8 ? 0 : 1 ] ] ;
  111.     return self ;
  112. }
  113.  
  114.  
  115. - drawIcon: (id) theIcon
  116. {
  117.     NXPoint            thePoint = { 8, 8 } ;
  118.  
  119.     [ [ [ NXApp appIcon ] contentView ] lockFocus ] ;
  120.     [ theIcon composite: NX_SOVER toPoint: &thePoint ] ;
  121.     [ [ [ NXApp appIcon ] contentView ] unlockFocus ] ;
  122.     [ [ NXApp appIcon ] flushWindow ] ;
  123.  
  124.     [ infoIcon lockFocus ] ;
  125.     [ theIcon composite: NX_SOVER toPoint: &thePoint ] ;
  126.     [ infoIcon unlockFocus ] ;
  127.     [ [ infoIcon window ] flushWindow ] ;
  128.  
  129.     return self ;
  130. }
  131.  
  132. @end
  133.